/**
 * @author ztl
 * @date 2017年1月14日下午5:54:38
 */
package com.zhihuishu.micro.course.openapi.cc.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import com.zhihuishu.micro.course.model.CourseAnalysisData;
import com.zhihuishu.micro.course.openapi.cc.CourseAnalysisDataOpenService;
import com.zhihuishu.micro.course.openapi.cc.dto.CourseAnalysisDataDto;
import com.zhihuishu.micro.course.service.CourseAnalysisDataService;
import com.zhihuishu.remote.RemoteResult;
import com.zhihuishu.toolkit.helper.BeanHelper;

/**
 * @description 课程数据分析Service 
 * @author ztl
 * 2017年1月14日
 */
@Service("courseAnalysisDataOpenServiceForcc")
public class CourseAnalysisDataOpenServiceImpl implements CourseAnalysisDataOpenService{

	@Resource
    private CourseAnalysisDataService courseAnalysisDataService;
	
	protected Logger logger=LoggerFactory.getLogger(getClass());
	
	@Override
	public RemoteResult<CourseAnalysisDataDto> getCourseAnalysisDataByCourseId(Long courseId, Long userId) {
		RemoteResult<CourseAnalysisDataDto> result = new RemoteResult<CourseAnalysisDataDto>();
		try {
			Assert.notNull(courseId, "课程id不能为空");
			Assert.notNull(userId, "课程id不能为空");
			CourseAnalysisData dtoResult = courseAnalysisDataService.getCourseAnalysisDataByCourseId(courseId, userId);
			result.setResult(BeanHelper.transTo(dtoResult, CourseAnalysisDataDto.class));
		} catch (Exception e) {
			result.setExceptionStack(e);
			result.setSuccess(false);
            logger.error("查询课程分析数据发生错误,参数信息为{}",courseId,e);
		}
		return result;
	}

	@Override
	public RemoteResult<List<Map<String, Object>>> getCourseListByUserId(Long userId) {
		RemoteResult<List<Map<String, Object>>> result = new RemoteResult<List<Map<String,Object>>>();
		try {
			Assert.notNull(userId, "用户id不能为空");
			List<Map<String, Object>> mapResult = courseAnalysisDataService.getCourseListByUserId(userId);
			result.setResult(mapResult);
		} catch (Exception e) {
			result.setExceptionStack(e);
			result.setSuccess(false);
            logger.error("查询课程列表发生错误,参数信息为{}",userId,e);
		}
		return result;
	}

}
